#region File Header
//----------------------------------------------------------------
// Copyright (C) 2002 Stefan Kyntchev
// All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR 
// FITNESS FOR A PARTICULAR PURPOSE.
//----------------------------------------------------------------
#endregion File Header

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AirWeb.WebControls.BandsControl
{
	/// <summary>
	/// Single band for the Bands control
	/// </summary>
	public class Band
	{
		string m_Name = ""; // the name of the band
		string m_URL = "";  // the url of the iframe
		bool m_default = false; // true if this is the default band
		BandsControl m_parent = null;  // reference to the parent BandsControl

		TableRow m_h = new TableRow();
		TableCell m_hc = new TableCell();

		TableRow m_c = new TableRow();
		TableCell m_cc = new TableCell();

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="i_name"></param>
		/// <param name="i_url"></param>
		/// <param name="i_default"></param>
		public Band(string i_name, string i_url, bool i_default)
		{
			m_Name = i_name;
			m_URL = i_url;
			m_default = i_default;
		}

		/// <summary>
		/// You can add controls directly to the content cell
		/// </summary>
		public TableCell ContentCell
		{
			get
			{
				return m_cc;
			}
		}

		/// <summary>
		/// Called by the parent AddBand to set the inverse reference to parent
		/// </summary>
		/// <param name="i_parent"></param>
		public void SetParent(BandsControl i_parent)
		{
			m_parent = i_parent;
		}
		
		/// <summary>
		/// Renders the band within the parent control
		/// </summary>
		public void Render()
		{
			// We must have parent 
			if(m_parent == null)
				return;

			// Create the header row
			if(m_default)
				m_h.ID = "__defaultBand";

			m_h.Attributes["onclick"] = "__onSelectBand(this)";

			// Create the header cell
			m_hc.Text = m_Name;
			m_hc.CssClass = m_parent.HeaderStyle;
			m_h.Cells.Add(m_hc);

			// Create the content row
			m_c.Style["display"] = "none";

			// Create the content cell.
			if(m_URL != "")
				m_cc.Text = "<iframe frameborder='no' height='100%' width='100%' src='" + m_URL + "'></iframe>";

			m_c.Cells.Add(m_cc);

			m_parent.BandsTable.Rows.Add(m_h);
			m_parent.BandsTable.Rows.Add(m_c);
		}
	}
}

